﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.Entity;
using BotonJXC.Util;
using NHibernate.Criterion;

namespace BotonJXC.DAO
{
    public class SettleAccountsDAO : NHibernateDao<SettleAccounts, int>
    {

        /// <summary>
        /// 根据条件查询结算款单
        /// </summary>
        /// <param name="begintime"></param>
        /// <param name="endtime"></param>
        /// <param name="settleAccounts"></param>
        /// <param name="start"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public PageModel<SettleAccounts> findSettleAccountsByCondition(DateTime? begintime, DateTime? endtime, SettleAccounts settleAccounts, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (begintime != null)
            {
                criterions.Add(Restrictions.Ge("CreateTime", begintime));
            }
            if (endtime != null)
            {
                criterions.Add(Restrictions.Le("CreateTime", endtime));
            }
            if (settleAccounts != null)
            {
                if (Utils.IsNotBlank(settleAccounts.SettleAccSn))
                {
                    criterions.Add(Restrictions.Like("SettleAccSn", settleAccounts.SettleAccSn, MatchMode.Anywhere));
                }
                if (settleAccounts.Supplier != null )
                {
                    criterions.Add(Restrictions.Eq("Supplier", settleAccounts.Supplier));
                }
                
                if (settleAccounts.Contract != null)
                {
                    criterions.Add(Restrictions.Eq("Contract", settleAccounts.Contract));
                }
                if (settleAccounts.OrgId > 0)
                {
                    criterions.Add(Restrictions.Eq("OrgId", settleAccounts.OrgId));
                }
                if (settleAccounts.OrgDepId > 0)
                {
                    criterions.Add(Restrictions.Eq("OrgDepId", settleAccounts.OrgDepId));
                }
               
            }
            return base.FindByPage(criterions.ToArray(), null, start, count);
        }

    }
}
